/*
 * @Description: 请描述此文件
 * @Author: LDM
 * @Date: 2021-09-03 18:11:05
 * @LastEditors: LDM
 * @LastEditTime: 2021-09-06 16:23:16
 */
import { computed } from 'vue'
import type { ComputedRef } from 'vue'
/**
 * @description: 引入vuex的module
 * @param {*}
 * @return {*}
 */
export function importVuexModules() {
  const exportStoreName = 'store'
  const modules = import.meta.globEager('../modules/**/index.ts')
  const vuexModules: any = []
  Object.keys(modules).forEach((key) => {
    const storeModule = modules[key][exportStoreName] || {}
    vuexModules.push(storeModule)
  })
  return vuexModules
}
/**
 * @description: 映射出仓库的state,并带computed
 * @param {*} store 取值的仓库
 * @param {*} keys 要取的所有
 * @return {ComputedRef} 返回 keys的所有Getter Computed格式
 */
export function mapState<T, U extends keyof T>(
  store: T,
  keys: UnionToTuple<U>
): { [k in U]: ComputedRef<T[k]> } {
  const map = {} as any
  for (const key of keys) {
    map[key] = computed(() => store[key as string])
  }
  return map
}
